<?php

	// TITLE: Home_owner_account AUTO MODEL
	// FILE: scaffolding/model/home_owner_account.php
	// AUTHOR: AUTOGEN
	// CREATED: 2015/04/20 07:49:57
	// DESCRIPTION: 
	// REQUIREMENTS: 

	$createHomeOwnerAccount = function($con, $homeOwnerAccount) {
		$sql = 'INSERT INTO home_owner_account (id, homeowner_id, type, bank_id, balance, account_number, routing_number) VALUES (';
		$sql .= $home_owner_account->getId() . ', ';
		$sql .= $home_owner_account->getHomeownerId() . ', ';
		$sql .= $home_owner_account->getType() . ', ';
		$sql .= $home_owner_account->getBankId() . ', ';
		$sql .= $home_owner_account->getBalance() . ', ';
		$sql .= $home_owner_account->getAccountNumber() . ', ';
		$sql .= $home_owner_account->getRoutingNumber() . ')';
		$sql .= ')';
		$result = mysqli_query($con, $sql);
		$id = ($result) ? mysqli_insert_id($con) : $result;
		mysqli_close($con);
		return $id;
	};

	$readHomeOwnerAccount = function($con, $id) {
		$sql = 'SELECT * FROM home_owner_account WHERE id = ' . $id;
		$results = mysqli_query($con, $sql);
		mysqli_close($con);
		if ($results) {
			$result = mysqli_fetch_array($results);
			$homeOwnerAccount = new HomeOwnerAccount();
			$homeOwnerAccount->setId(result[0]);
			$homeOwnerAccount->setHomeownerId($dbio->select($readHomeowner(result[1])));
			$homeOwnerAccount->setType(result[2]);
			$homeOwnerAccount->setBankId($dbio->select($readBank(result[3])));
			$homeOwnerAccount->setBalance(result[4]);
			$homeOwnerAccount->setAccountNumber(result[5]);
			$homeOwnerAccount->setRoutingNumber(result[6]);
		} else {
			$homeOwnerAccount = false;
		}
		return $homeOwnerAccount;
	};

	$updateHomeOwnerAccount = function($con, $homeOwnerAccount) {
		$sql = 'UPDATE home_owner_account SET ';
		$sql .= 'id = ' . $home_owner_account->getId() . ', ';
		$sql .= 'homeowner_id = ' . $home_owner_account->getHomeownerId() . ', ';
		$sql .= 'type = ' . $home_owner_account->getType() . ', ';
		$sql .= 'bank_id = ' . $home_owner_account->getBankId() . ', ';
		$sql .= 'balance = ' . $home_owner_account->getBalance() . ', ';
		$sql .= 'account_number = ' . $home_owner_account->getAccountNumber() . ', ';
		$sql .= 'routing_number = ' . $home_owner_account->getRoutingNumber() ;
		$sql .= 'WHERE id = ' . id;
		$result = mysqli_query($con, $sql);
		mysqli_close($con);
		return $result;
	};

	$deleteHomeOwnerAccount = function($con, $id) {
		$sql = 'DELETE FROM home_owner_account WHERE id = ' . $id;
		$result = mysqli_query($con, $sql);
		mysqli_close($con);
		return $result;
	};

	$listHomeOwnerAccount = function($con) {
		$sql = 'SELECT * FROM home_owner_account';
		$results = mysqli_query($con, $sql);
		mysqli_close($con);
		if ($results) {
			$homeOwnerAccounts = array();
			while ($result = mysqli_fetch_array($results)) {
				$homeOwnerAccount = new HomeOwnerAccount();
				$homeOwnerAccount->setId(result[0]);
				$homeOwnerAccount->setHomeownerId($dbio->select($readHomeowner(result[1])));
				$homeOwnerAccount->setType(result[2]);
				$homeOwnerAccount->setBankId($dbio->select($readBank(result[3])));
				$homeOwnerAccount->setBalance(result[4]);
				$homeOwnerAccount->setAccountNumber(result[5]);
				$homeOwnerAccount->setRoutingNumber(result[6]);
				$homeOwnerAccounts[] = homeOwnerAccount;
			}// end while
		} else {
			$homeOwnerAccounts = false;
		}
		return $homeOwnerAccounts;
	};

